package com.example.demo.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaMode;
import com.example.demo.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/*
 *
 *   @Author: SJY
 *   @Date: 2024/4/9-04-09-18:48
 *   权限的讲解
 */
@Api(tags = "权限测试")
@RestController
@RequestMapping("/privilege")
public class PrivilegeController {


    @ApiOperation(value = "对学生角色的校验")
    @SaCheckRole("student")
    @GetMapping("/test1")
    public Result getTest1(){
        return Result.success("学生才能访问，成功获取到数据");
    }

    @ApiOperation(value = "对老师角色的校验")
    @SaCheckRole("class_teacher")
    @GetMapping("/test2")
    public Result getTest2(){
        return Result.success("老师才能访问，成功获取到数据");
    }

    @ApiOperation(value = "对校长角色的校验")
    @SaCheckRole("principal")
    @GetMapping("/test3")
    public Result getTest3(){
        return Result.success("校长才能访问，成功获取到数据");
    }

    // 必须同时是老师和校长才能访问
    @ApiOperation(value = "校长+老师角色的校验")
    // 必须同时是两种身份才能访问
    @SaCheckRole(value = {"principal","class_teacher"},mode = SaMode.AND)
    @GetMapping("/test4")
    public Result getTest4(){
        return Result.success("必须是校长和老师才能访问");
    }

    // 学生和老师都可访问
    @ApiOperation(value = "学生和老师都可访问")
    // 必须同时是两种身份才能访问
    @SaCheckRole(value = {"class_teacher","student"},mode = SaMode.OR)
    @GetMapping("/test5")
    public Result getTest5(){
        return Result.success("学生和老师都可访问");
    }

    //==================================权限篇=======================================
    //学费菜单
    @ApiOperation(value = "学费的金额修改")
    @SaCheckPermission("tuition.update.money")
    @GetMapping("/test6")
    public Result getTest6(){
        return Result.success("金额已经修改");
    }

}
